package ntu.metaweb.result;

import ntu.metaweb.storage.WebPageQuery;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("link")
public class Link {
	@XStreamAlias("usernum")
	public int userNum;
	public String comment;
	@XStreamAlias("own")
	public boolean ownLink;
	@XStreamAlias("pagerating")
	public double pageRating;
	public String url;
	@XStreamAlias("urlparam")
	public String urlParam;
	@XStreamAlias("title")
	public String pageTitle;
	@XStreamAlias("linkrating")
	public int linkRating;

	public Link (String user, boolean incoming, ntu.metaweb.storage.Link link) {
		this.userNum = link.getContributors().size();
		this.ownLink = link.getContributors().contains(user);
		this.linkRating = link.getTotalRating();
		this.url = incoming ? link.getFromURL().toExternalForm() 
				: link.getToURL().toExternalForm();
		this.urlParam = "";
		this.pageTitle = link.getTitle().length() == 0 ? url : link.getTitle();
		this.pageRating = link.getPageRating();
		if (user != null) {
			this.comment = link.getUserNote(user);
		}
	}
}
